`<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>客户体检信息健康管理系统</title>
    <meta name="description" content="客户体检信息健康管理系统">
    <meta name="keywords" content="客户体检信息健康管理系统">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index_copy.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>预约列表</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <!--档案号/-->
                <el-input placeholder="名称/手机号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()"
                           v-if="this.user.roles[0].keyword == 'ROLE_ADMIN'">新建
                </el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center"></el-table-column>
                <el-table-column prop="orderDate" :formatter="dateFormat" label="预约日期" align="center"></el-table-column>
                <!--                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>-->
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="setmealName" label="套餐名称" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">确认预约</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">取消预约</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataAddFrom" :model="formData" label-position="right" :rules="rules"
                                         label-width="100px">
                                    <el-row>
                                        <!-- <el-col :span="12">
                                             <el-form-item label="档案号" prop="fileNumber">
                                                 <el-input v-model="formData.fileNumber"/>
                                             </el-form-item>
                                         </el-col>-->
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>

                                        <el-col :span="12">
                                            <el-form-item label="手机号码" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="预约时间" prop="orderDate">
                                                <!--                                                        <el-input v-model="formData.orderDate"/>-->
                                                <el-date-picker :picker-options="pickerOptions" type="date"
                                                                v-model="formData.orderDate"></el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                       <!-- <el-col :span="12">
                                            <el-form-item label="预约类型" prop="orderType">
                                                <el-select v-model="formData.orderType">
                                                    <el-option label="微信预约" value="微信预约"></el-option>
                                                    <el-option label="电话预约" value="电话预约"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>-->
                                        <el-col :span="12">
                                            <el-form-item label="性别" prop="sex">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                   <!-- <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="身份证号" prop="idCard">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>-->
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="注意事项" prop="attention">
                                                <el-input v-model="formData.attention" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>

                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th style="width: 50px;text-align:center;">选择</th>
                                            <!--<th style="width: 80px;text-align:center;">项目编码</th>-->
                                            <th style="text-align:center;">项目名称</th>
                                            <th style="text-align:center;">项目说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td style="text-align:center;">
                                                <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                            </td>
                                           <!-- <td style="text-align:center;"><label :for="c.id">{{c.code}}</label></td>-->
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>

                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd('dataAddFrom')">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <!--<div class="add-form">
                <el-dialog title="编辑用户" :visible.sync="dialogFormVisibleEdit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="用户名">
                                                <el-input v-model="formData.username"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="联系电话">
                                                <el-input v-model="formData.telephone"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="生日">
                                                <el-date-picker
                                                        v-model="formData.birthday"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="选择等级">
                                                <el-select v-model="formData.gender">
                                                    <el-option label="不限" value="0"></el-option>
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="是否启用">
                                                <el-checkbox v-model="station"
                                                             @change="changeStatus()"></el-checkbox>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="备注">
                                                <el-input v-model="formData.remark" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="角色信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>角色名称</th>
                                            <th>角色关键字</th>
                                            <th>角色说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="setmealIds" type="checkbox"
                                                       :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.keyword}}</label></td>
                                            <td><label :for="c.id">{{c.description}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisibleEdit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>-->
        </div>
    </div>
</div>
</body>

<script>
    const vm = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            checked: true,
            dataList: [],//列表数据
            formData: {},//表单数据
            station: false,
            parentMenuList: [],
            user: "",
            pickerOptions: {
                /*disabledDate(time) {
                    const times = new Date(new Date().toLocaleDateString()).getTime() + 30 * 8.64e7 - 1
                    return time.getTime() < Date.now() - 8.64e7 || time.getTime() > times// 如果没有后面的-8.64e7就是不可以选择今天的
                }*/
                disabledDate(time) {
                    let now = new Date();   //获取此时的时间
                    let nowData = new Date(  //获取此时年月日的后一天
                        now.getFullYear(),
                        now.getMonth(),
                        now.getDate() + 1 //获取明天
                    );
                    let oneMonthAgo = new Date(  //获取一个月之前的时间
                        now.getFullYear(),
                        now.getMonth() + 1,  //获取上一个月
                        now.getDate() + 1   //将多算的一天减掉
                    );

                    /*return (
                        time.getTime() > nowData.getTime() - 1000  //可以选择到今天的xxx:xxx:xxx:23:59:59，只有的全部disabled
                        || time.getTime() < oneMonthAgo.getTime()  //小于一个月的全部disabled掉
                    );*/
                    return time.getTime() > oneMonthAgo || time.getTime() < nowData
                }
            },
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            setmealIds: [],//新增和编辑表单中角色对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisibleEdit: false,//控制编辑窗口显示/隐藏,
            rules: {//校验规则
                /*fileNumber: [{
                    required: true, message: '档案号为必填项', trigger: 'blur',
                }],*/
                name: [{required: true, message: '姓名为必填项', trigger: 'blur'}],
                sex: [{required: true, message: '性别为必选项', trigger: 'change'}],
                // orderType: [{required: true, message: '预约类型为必选项', trigger: 'change'}],
                phoneNumber: [{
                    required: true, message: '手机号码为必填项', trigger: 'blur'
                }, {min: 11, max: 11, message: '手机号码格式错误', trigger: 'blur'}],
                /*idCard: [{
                    required: true, message: '身份证为必填项', trigger: 'blur'
                }],*/
                orderDate: [{required: true, message: '预约时间为必选项', trigger: 'blur'}],
                attention: [{required: true, message: '注意事项为必填项', trigger: 'blur'}]
            }
        },
        created() {
            this.user = JSON.parse(localStorage.getItem("userInfo"));
            this.findPage();
        },
        methods: {
            dateFormat(row, column) {
                let t = new Date(row.orderDate);//row 表示一行数据, updateTime 表示要格式化的字段名称
                return t.getFullYear() + "年" + (t.getMonth() + 1) + "月" + t.getDate() + "日";
            },
            changeStatus() {
                this.station = !!this.station
                this.formData.station = 1 ? this.station : !!this.station
            },
            //添加
            handleAdd(forName) {
                // console.log(forName)
                //表单校验
                this.$refs[forName].validate((valid) => {
                    if (!valid) {
                        return false;
                    }
                    if (this.setmealIds.length <= 0) {
                        this.$message({
                            message: '一个预约必须拥有一个套餐',
                            type: 'warning'
                        });
                        return;
                    }
                    if (this.setmealIds.length > 1) {
                        this.$message({
                            message: '一次只能预约一个套餐',
                            type: 'warning'
                        });
                        return;
                    }

                    //校验表单输入项是否合法
                    //表单数据校验通过，发送ajax请求将表单数据提交到后台
                    axios.post("/orderSetting/add.do?checkSetmealId=" + this.setmealIds[0], this.formData).then((response) => {
                        // console.log(response)
                        //隐藏新增窗口
                        this.dialogFormVisible = false;
                        //判断后台返回的flag值，true表示添加操作成功，false为添加操作失败
                        if (response.data.flag) {
                            this.$message({
                                message: response.data.message,
                                type: 'success'
                            });
                        } else {
                            this.$message.error(response.data.message);
                        }
                    }).finally(() => {
                        //重新查询
                        this.findPage();
                    });
                });

            },
            //分页查询
            async findPage() {
                if (this.user.roles[0].keyword == 'ROLE_HEALTH_MANAGER') {
                    let result = await axios.post("/orderSetting/findPage.do?userName=" + this.user.username, this.pagination);
                    this.dataList = result.data.rows
                    //过滤查询
                    this.dataList = this.dataList.filter((item) => {
                        //过滤条件:判断健康管理师的Id是否与预约对象的ID相同
                        // console.log(item.userId == this.user.id)
                        return item.userId == this.user.id
                    })
                    this.pagination.total = this.dataList.length
                } else {
                    let result = await axios.post("/orderSetting/findPage.do?userName=" + null, this.pagination);
                    this.dataList = result.data.rows
                    this.pagination.total = result.data.total
                }

            },
            // 重置表单
            resetForm() {
                if (this.$refs['dataAddFrom'] !== undefined) {
                    this.$refs['dataAddFrom'].resetFields();
                }
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm()
                this.dialogFormVisible = true
                //默认切换到第一个标签页（基本信息）
                this.activeName = 'first';
                //查询检查项列表数据
                //重置
                this.setmealIds = [];
                //发送ajax请求查询所有套餐
                axios.get("/setmeal/queryAll.do").then((res) => {
                    if (res.data.flag) {
                        //将检查项列表数据赋值给模型数据用于页面表格展示
                        this.tableData = res.data.data;
                    } else {
                        this.$message.error(res.data.message);
                    }
                });

            },
            // 弹出编辑窗口
            handleUpdate(row) {
                //回显数据，通过发送ajax请求根据电话号码查询当前检查项数据
                axios.get("/orderSetting/arrived.do?id=" + row.id).then((res) => {
                    //判断这个controller是否执行成功
                    if (res.data.flag) {
                        //重新进行分页查询
                        this.findPage();
                    } else {
                        //查询失败，弹出提示
                        this.$message.error(res.data.message);
                    }
                }).catch((r) => {
                    this.showMessage(r);
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage
                this.findPage()
            },
            // 删除
            handleDelete(row) {
                // console.log(row)
                this.$confirm('确认取消预约吗？', '提示', {type: 'warning'}).then(async () => {
                    let result = await axios.post("/orderSetting/delete.do", row);
                    if (!result.data.flag) {
                        //删除失败
                        this.$message.error(result.data.message)
                    } else {
                        //删除成功
                        this.$message({
                            message: result.data.message,
                            type: 'success'
                        });
                        await this.findPage();

                    }
                }).catch((error) => {
                    // alert("点击了取消按钮");
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    });
                })
            }
        }
    })
</script>
</html>
`